package com.woniuxy.repay.service.impl;

import com.woniuxy.entity.RepaymentOverdue;
import com.woniuxy.entity.RepaymentProtection;
import com.woniuxy.repay.entity.PageBean;
import com.woniuxy.repay.mapper.RepaymentProtectionMapper;
import com.woniuxy.repay.service.RepaymentProtectionService;
import com.woniuxy.repay.tools.ServiceTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shichen
 * @create 2021-11-21-20:42
 * @description
 */
@Slf4j
@Service
public class RepaymentProtectionServiceImpl implements RepaymentProtectionService {


    @Resource
    RepaymentProtectionMapper repaymentProtectionMapper;

    @Override
    public PageBean selectByCondition(RepaymentProtection repaymentProtection, Integer pageIndex) {
        List<RepaymentProtection> repaymentProtections = repaymentProtectionMapper.selectByCondition(repaymentProtection);
        List dataList = ServiceTool.createDataList(repaymentProtections, pageIndex);
        return new PageBean(repaymentProtections.size(), 5, pageIndex, dataList);
    }

    @Override
    public void updateByCondition(RepaymentProtection repaymentProtection) {
        // 二重校验 ， 第一次校验在 controller
        if (repaymentProtection.getId() != null) {
            repaymentProtectionMapper.updateByCondition(repaymentProtection);
        }

        // return selectAll(1);
    }

    @Override
    public void insert(RepaymentProtection repaymentProtection) {
        repaymentProtectionMapper.insertByCondition(repaymentProtection);
        //return selectAll(1);
    }


}
